﻿using UnityEngine;
using System.Collections;

/**
 * 本教程演示如何在 Unity 项目中获取用于输入的按钮或键，以及这些轴的行为或如何通过 Unity Input Manager 进行修改
 */
public class KeyInput : MonoBehaviour
{
    public GUITexture graphic;
    public Texture2D standard;
    public Texture2D downgfx;
    public Texture2D upgfx;
    public Texture2D heldgfx;
    
    void Start()
    {
        graphic.texture = standard;
    }
    
    void Update ()
    {
        
        //GetButton 和GetKey 类似。
        bool down = Input.GetKeyDown(KeyCode.Space);
        bool held = Input.GetKey(KeyCode.Space);   //持续检测按钮按下状态，（一直按住则一直是true状态）
        bool up = Input.GetKeyUp(KeyCode.Space);   //Input.GetKeyUp("Jump");  在设置中Jump中定义为Space按钮 
        
        if(down)
        {
            graphic.texture = downgfx;
        }
        else if(held)
        {
            graphic.texture = heldgfx;
        }
        else if(up)
        {
            graphic.texture = upgfx;
        }
        else
        {
            graphic.texture = standard; 
        }
        
        guiText.text = " " + down + "\n " + held + "\n " + up;
    }
}